//
//  PathHelper.m
//  DialectShare
//
//  Created by timmy zhong on 3/20/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "PathHelper.h"

@implementation PathHelper
+ (NSString *)baseUrl
{
    NSString *url = @"http://dialect.sinaapp.com/index.php?";
    return url;
}

+ (NSString *)documentDir
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    return basePath;
}
+ (NSString *)cacheDir
{
    NSString *directory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    return directory;
}

+ (NSString *)fileNameForUrl:(NSString *)url
{
    if ([url hasPrefix:@"http://"]) {
        url = [url substringFromIndex:[@"http://" length]];
    }
    NSArray *components = [url componentsSeparatedByString:@"/"];
    NSString *name = [components componentsJoinedByString:@"_"];
    return name;
}

+ (NSString *)dbPath
{
    return [[PathHelper documentDir] stringByAppendingPathComponent:@"ds.db"];
}

@end
